﻿using System;
using System.Collections.Generic;
using System.Text;

namespace IllustratedCsharp7_ch16
{
    interface ILiveBirth        //声明接口
    {
        string BabyCalled();
    }
    class Animal { }            //基类Animal
    class Cat : Animal, ILiveBirth
    {
        string ILiveBirth.BabyCalled()
        { return "iktten"; }       
    }
    class Dog : Animal, ILiveBirth
    {
        string ILiveBirth.BabyCalled()
        { return "puppy"; }
    }
    class Bird : Animal
    {
    }

    class chapt16_12_ExamplesOfDifferentClassesImplementingAnInterface
    {
       
        static void Main()
        {
            Animal[] animalArray = new Animal[3];   //创建Animal数组
            animalArray[0] = new Cat();
            animalArray[1] = new Dog();
            animalArray[2] = new Bird();

            foreach (Animal a in animalArray)
            {
                ILiveBirth b = a as ILiveBirth; //如果实现了ILiveBirth......
                if (b != null)
                    Console.WriteLine($"Baby is caled: {b.BabyCalled()}");
            }
        }
    }
}
